<?php
include_once '../Controller/ConnectFB.php';
require '../Controller/Config.php';
$ses_id = session_id(); 
$_SESSION['ACCESS_PAGE_ID'] = $ses_id;
?>
<!DOCTYPE html>
<html>
 <head>
    <title></title>
    <meta charset="UTF-8">
    <link rel="shortcut icon" href="../icon/favicon.ico"/>
    <script language="JavaScript" src="../jquery/js/jquery-1.9.1.js" type="text/javascript"></script>
    <script language="JavaScript" src="../jquery/js/jquery-ui-1.10.1.custom.js" type="text/javascript"></script>
    <link rel="stylesheet" type="text/css" href="../css/fixedMenu_style2.css" />
    <link rel="stylesheet" href="../css/myStyle.css" type="text/css" />
<!--    <style>
        #linkList{
            list-style: none;
            line-height: 22px;
            margin-left: -5%;
        }
    </style>-->
</head>

<?php

if(is_null($fb_userData['id'])){
?>
    <script language=javascript>window.open('<?php echo $loginUrl ?>','','width=500,height=350')</script> 
<?php
    exit();
}else{
$userId = $fb_userData['id'];
}
//$userId = 1008;

$page = "";

if(isset($_GET['page'])){
    $page = $_GET['page'].".php";
}else{
    $page = "AnswerNo.php";
}

?>
<style>
body
{
        background-image:url('../images/bg.jpg');
        background-repeat:repeat-x;
        background-color:#f8e3b7;
        
        
}
</style>
    </head>
<body>

<table border="0" width="80%" height="650px" align="center" cellpadding="5" cellspacing="1" bgcolor="#404040">
  <tr height="30px">
    <td colspan="2" bgcolor="#ffffff">
        <div class="menu">
            <ul align="left">
            <table align="left" border="0">
                <tr>
                    <td>
                        <a href="../Interface/MenuHome.php">Home</a>
                    </td>
                </tr>
            </table>
            

            <table align="left" border="0">
                <tr>
                    <td>
                <a href="../Interface/MenuCreatePoll.php">Create Poll</a>
                    </td>
                </tr>
            </table>

            <table align="left" border="0">
                <tr>
                    <td>
                <a href="../Interface/MenuAnswer.php">Answer Poll</a>
                    </td>
                </tr>
            </table>
            
            <table align="left" border="0">
                <tr>
                    <td>
                <a href="../View/Compensation.php">Compensation</a>
                    </td>
                </tr>
            </table>
            
            <table align="left" border="0">
                <tr>
                    <td>
                <a href="../View/Statistics.php">Statistics</a>
                    </td>
                </tr>
            </table>    
                
           <table align="left" border="0">
                <tr>
                    <td>
                <a href="../Interface/MenuAbout.php">About</a>
                    </td>
                </tr>
            </table>
            
            <table align="left" border="0">
                <tr>
                    <td>
                <a href="../Interface/MenuContact.php">Contact</a>
                    </td>
                </tr>
            </table>
        </ul>
            
            <ul align="right"> 
            <?php if($fb_user){?>
               <table align="right" border="0" >
                   <tr>
                       <td>
                           <img width="25px" higth="25px"  src="https://graph.facebook.com///<?php echo $fb_user?>/picture">
                       </td>
                       <td>
                       <font color="white" size="2" align="left"><?php echo $_SESSION['strName'] ?></font>
                <a href="<?php echo $logoutUrl?>" >Logout</a>
                </table>
                <?php }else{?>
                <table align="right" border="0" >
                    <tr>
                        <td>
                    <a href="javascript:popup('<?php echo $loginUrl?>','',500,350);">Login with Facebook</a>
                        </td>
                       </tr>
                   </table>
                <?php } ?>
              </ul> 
        </div>
    </td>
  </tr>
  <tr  valign="top">
    <td width="45%" align="left" valign="top" bgcolor="#ffffff">
       <?php

                    $q="SELECT answer.answer_id,answer.poll_id,poll.poll_title,answer.answer_date,poll.compensation FROM answer 
                        LEFT JOIN poll ON poll.poll_id = answer.poll_id WHERE answer.user_id = '".$userId."' GROUP BY answer.poll_id";
                    $qr=mysql_query($q);
                    $num_rows = @mysql_num_rows($qr);
//                    echo $q;
                    if($num_rows==0){
                        
                        ?>
                    <table width="100%" border="0" align="center">
                            <tr valign="top" height="40px">
                                <td colspan="3" border="1" align="center" bgcolor="#e96c10" valign="middle">
                                    <font color="#ffffff" size="4" align="center"><b>แบบสอบถามที่ท่านเคยตอบ</b></font>
                                </td>
                            </tr>
                            <tr>
                                <td align="center">
                                    <font size="4" align="left">ไม่มีแบบสอบถามที่ท่านเคยตอบ</font>
                                </td>
                            </tr>
                    </table>
                        <?php    
                    }else{
                        $count = 1;
                        ?>
                        <table width="100%" border="0" align="center">
                            <tr valign="top" height="40px">
                                <td colspan="3" border="1" align="center" bgcolor="#e96c10" valign="middle">
                                     <font color="#ffffff" size="4" align="left"><b>แบบสอบถามที่ท่านเคยตอบ</b></font>
                                </td>
                            </tr>
                        <tr align="center" bgcolor="#ee974a" height="30px">
                            <td>
                                <font color="#ffffff"><b>ลำดับที่</b></font>
                            </td>
                            <td>
                                <font color="#ffffff"><b>ชื่อแบบสอบถาม</b></font>
                            </td>
                            <td>
                                <font color="#ffffff"><b>วันที่ตอบ</b></font>
                            </td>
                           
                        </tr>
                        <?php
                        while($rs=mysql_fetch_array($qr)){  
                            $date = new DateTime($rs['answer_date']);
                            
                 if($count%2==0){
                            $bgcolor = "#ffffff";
                        }else{
                            $bgcolor = "#f6d6a5";
                        } 
                ?>      
                        <tr align="center" bgcolor="<?php echo $bgcolor ?>" height="25px">
                            <td>
                                <font><?php echo $count?></font>
                            </td>
                            <td>
                                <font><a href="?page=ViewAnswer&pollId=<?php echo $rs['poll_id']?>&poll=<?php echo $rs['poll_title']?>&sid=<?php echo $ses_id ?>" ><?php echo $rs['poll_title']?></a></font>
                            </td>
                            <td>
                                <font><?php echo $date->format("d/m/Y")?></font>
                            </td>                        
                        </tr>
                     
                <?php 
                            $count++;
                        }
                        mysql_close();
                        ?>
                        </table>
                        <?php
                        
                    }
                
                ?>
                         
    </td>
    <td align="left" valign="top" bgcolor="#ffffff">
            <?php require '../View/'.$page; ?>        
    </td>
  </tr>
</table>

</body>
</html>